package com.shixj.demo.barrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * Created by shixj on 2017/9/25.
 */
public class Counter implements Runnable {
    private  final int index;
    private  final CyclicBarrier barrier;

    public Counter(int index, CyclicBarrier barrier) {
        this.index = index;
        this.barrier = barrier;
    }

    @Override
    public void run() {
        System.out.println(index+"已到！");
        try {
            barrier.await();//等待其他哥们
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
}
